package com.ibp.other;

import java.util.concurrent.TimeUnit;

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ConnectionCleaner extends Thread {
    
	Logger logger = LoggerFactory.getLogger(ConnectionCleaner.class);
	
    private PoolingHttpClientConnectionManager connectionManager;
	
	public ConnectionCleaner(PoolingHttpClientConnectionManager connectionManager){
		this.connectionManager = connectionManager ;
	}
	
	
	@Override
	public void run(){
		while(true){
			try {
				logger.error("http连接清理开始");
				sleep(600*1000);
				this.connectionManager.closeExpiredConnections();
				this.connectionManager.closeIdleConnections(60, TimeUnit.SECONDS);
			} catch (InterruptedException e) {
				logger.error("http清理线程执行出错:{}",e);
			}

		}
	}
	
}
